﻿

namespace Jhong.FunMVCBlog.Core.Data
{
    using Jhong.FunMVCBlog.Core.Entity;
    using Jhong.FunMVCBlog.Core.Infrastructure;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    public class AttachmentData : BaseData
    {
        public PageContainer<Attachment> GetList(int pageIndex, int itemsPerPage)
        {
            if (pageIndex < 1) pageIndex = 1;
            if (itemsPerPage < 1) itemsPerPage = 10;
            using (this._dbContext)
            {
                var items = this._dbContext.T("SELECT * FROM attachment  order by CreateTime Desc LIMIT @0,@1", (pageIndex - 1) * itemsPerPage, itemsPerPage).QueryToEntitys<Attachment>();
                var totalCount = this._dbContext.T("SELECT count(*) FROM attachment").QueryFirstOrDefault<int>();
                var container = new PageContainer<Attachment>(pageIndex, itemsPerPage, totalCount, items);
                return container;
            }
        }

        public Attachment GetByID(Guid id)
        {
            using (this._dbContext)
            {
                return this._dbContext.T("select * from attachment where ID=@0", id).QueryFirstOrDefault<Attachment>();
            }
        }


    }
}
